import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

public class WaitDemo5 {
    public static void main(String[] args) {
        Object lock=new Object();
        Object lock2=new Object();
//        new Thread(()->{
//            System.out.println("线程1:开始执行");
//            synchronized (lock){
//                try {
//                    lock.wait();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println("线程1：执行完成");
//            }
//        },"无参wait方法").start();

        new Thread(()->{
            synchronized (lock2){
                System.out.println("线程2:开始执行"+ LocalDateTime.now());
                try {
                    lock2.wait(60*60*60*1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程2：执行完成"+LocalDateTime.now());
            }
        },"有参wait方法").start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock2){
                System.out.println("唤醒线程2");
                lock2.notify();
            }
        }).start();
    }
}
